#include <bits/stdc++.h>
using namespace std;

int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
        x = x * 10 + ch - '0', ch = getchar();
    return x * f;
}

void write(int x)
{
    if (x < 0)
    {
        putchar('-');
        write(-x);
        return;
    }
    if (x / 10)
        write(x / 10);
    putchar(x % 10 + '0');
}

const int N = 1e5 + 5;
int T, n, m, L, V, d[N], v[N], a[N], p[N], tot, used[N], cnt;
double l[N], r[N];
struct Node
{
    // int id;
    double l, r;
    int typ;// 1:(,] 0:[,) 2:[]
    friend bool operator < (Node M1, Node M2)
    {
        return M1.r < M2.r;
    }
}x[N];

bool f(int t, Node x)
{
    if (x.typ == 1)
        return (x.l < t && t <= x.r);
    if (x.typ == 0)
        return (x.l <= t && t < x.r);
    return (x.l <= t && t <= x.r);
}

bool A()
{
    for (int i = 1; i <= n; i++)
        if (a[i] != 0)
            return false;
    return true;
}

void workA()
{
    int num = 0;
    for (int i = 1; i <= n; i++)
        if (v[i] > V && d[i] <= p[m])
        {
            num++;
        }
    printf("%d %d\n", num, m - 1);
}

bool B()
{
    for (int i = 1; i <= n; i++)
        if (a[i] < 0)
            return false;
    return true;
}

void workB()
{
    for (int i = 1; i <= n; i++)
    {
        x[i].typ = 1;
        if (v[i] >= V)
        {
             x[i].l = d[i];
             x[i].r = L;//(l, r]
             continue;
        }
        x[i].l = d[i] + (V * V - v[i] * v[i]) * 1.0 / 2 / a[i];
        x[i].r = L;
        if (x[i].l > L)
            x[i].l = x[i].r = L + 1;
    }
    int num = 0;
    for (int i = 1; i <= n; i++)
    {
        if (x[i].l <= p[m])
            num++;
    }
    printf("%d %d\n", num, m - 1);
}

int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    T = read();
    while (T--)
    {
        n = read(), m = read(), L = read(), V = read();
        for (int i = 1; i <= n; i++)
            d[i] = read(), v[i] = read(), a[i] = read();
        for (int i = 1; i <= m; i++)
            p[i] = read();
        // cin >> n >> m >> L >> V;
        // for (int i = 1; i <= n; i++)
        //     cin >> d[i] >> v[i] >> a[i];
        // for (int i = 1; i <= m; i++)
        //     cin >> p[i];
        if (A())
        {
            workA();
        }
        else if (B())
        {
            workB();
        }
        // else if (C())
        // {
        //     workC();
        // }
        else
        {
            for (int i = 1; i <= n; i++)
            {
                // x[i].id = i;
                if (a[i] == 0)
                {
                    if (v[i] <= V)
                    {
                        x[i].l = x[i].r = L + 1;
                        continue;
                    }
                    x[i].l = d[i];
                    x[i].r = L;
                    x[i].typ = 2;
                }
                else if (a[i] < 0)
                {
                    if (v[i] <= V)
                    {
                        x[i].l = x[i].r = L + 1;
                        continue;
                    }
                    x[i].l = d[i];
                    x[i].r = d[i] + (V * V - v[i] * v[i]) * 1.0 / 2 / a[i];
                    if (x[i].r > L)
                    {
                        x[i].r = L;
                        x[i].typ = 2;
                    }
                }
                else
                {
                    x[i].typ = 1;
                    if (v[i] >= V)
                    {
                        x[i].l = d[i];
                        x[i].r = L;//(l, r]
                        continue;
                    }
                    x[i].l = d[i] + (V * V - v[i] * v[i]) * 1.0 / 2 / a[i];
                    x[i].r = L;
                    if (x[i].l > L)
                        x[i].l = x[i].r = L + 1;
                }
            }
            sort (x + 1, x + 1 + n);
            tot = n;
            while (x[tot].l == L + 1 && x[tot].r == L + 1)
                tot--;
            cnt = 0;
            int ans = 0;
            // for (int i = 1; i <= tot; i++)
            // {
            //     bool fl = false;
            //     for (int j = cnt; j >= 1; j--)
            //         if (f(p[used[j]], x[i]))
            //         {
            //             fl = true;
            //             ans++;
            //             // cout << x[i].id << endl;
            //             break;
            //         }
            //     if (!fl)
            //     {
            //         for (int j = used[cnt] + 1; j <= m; j++)
            //             if (f(p[j], x[i]))
            //             {
            //                 while (j + 1 <= m && f(p[j + 1], x[i]))
            //                     j++;
            //                 used[++cnt] = j;
            //                 ans++;
            //                 // cout << x[i].id << endl;
            //                 break;
            //             }
            //     }
            // }
            // for (int i = 1; i <= cnt; i++)
            //     cout << used[i] << endl;
            int last = 0;
            for (int i = 1; i <= tot; i++)
            {
                for (int j = last + 1; j <= m; j++)
                {
                    if (f(p[j], x[i]))
                    {
                        while (j + 1 <= m && f(p[j + 1], x[i]))
                            j++;
                        ans++;
                        while (i + 1 <= tot && f(p[j], x[i + 1]))
                            i++, ans++;
                        last = j;
                        cnt++;
                        break;
                    }
                }
            }
            printf("%d %d\n", ans, m - cnt);            
        }

    }
    return 0;
}